﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using T.FAS.Runtime.Base.Entity;
using T.FAS.Runtime.Metadata.Entity.DataModel;

namespace T.FAS.Runtime.Metadata.Entity.Page
{
    public class DependencyDQ
    {
        /// <summary>
        /// DataQuery
        /// </summary>
        public DataQuery MetaData { get; set; }
        /// <summary>
        /// ActionType
        /// </summary>
        public ActionType ActionType
        {
            get
            {
                return ActionType.DataQuery;
            }
        }
        /// <summary>
        /// 旧Schema表达式
        /// </summary>
        public string OldTopRefSchemaExpr { get; set; }
        /// <summary>
        /// 新Schema表达式
        /// </summary>
        public string NewTopRefSchemaExpr { get; set; }
        /// <summary>
        /// DataSourceType
        /// </summary>
        public string DataSourceType
        {
            get
            {
                return "Action";
            }
        }
        private List<ViewModelParameter> _Parameters = null;
        /// <summary>
        /// Parameters
        /// </summary>
        public List<ViewModelParameter> Parameters
        {
            get
            {
                if (_Parameters == null || _Parameters.Count <= 0)
                {
                    List<ViewModelParameter> parameters = new List<ViewModelParameter>();
                    if (MetaData.DataQueryParams != null)
                    {
                        var queryParams = MetaData.DataQueryParams.Where(t => t.IsInputParam).ToList();
                        foreach (var param in queryParams)
                        {
                            parameters.Add(new ViewModelParameter
                            {
                                ID = Guid.NewGuid().ToString(),
                                Code = param.Code,
                                DataType = param.ParamType,
                                Name = param.Name,
                                Value = param.DefaultValue,
                            });
                        }
                    }
                    _Parameters = parameters;
                }
                return _Parameters;
            }
        }
        private string _DisplayName = null;
        /// <summary>
        /// DisplayName
        /// </summary>
        public string DisplayName
        {
            get
            {
                if (string.IsNullOrEmpty(_DisplayName))
                {
                    _DisplayName = $"{ActionType}.{MetaData.MetaDataCode}({string.Join(",", Parameters.Select(t => t.Code))})";
                }
                return _DisplayName;
            }
        }
        public List<TAttribute> AddTAttributes { get; set; } = new List<TAttribute>();
        public List<DataQueryColumn> AddColumns { get; set; } = new List<DataQueryColumn>();
        public List<DataQueryColumn> DeleteColumns { get; set; } = new List<DataQueryColumn>();
        public List<ChangeDataQueryColumn> ModifyColumns { get; set; } = new List<ChangeDataQueryColumn>();
    }
}
